﻿Public Class FormTrangThai

    Private Sub FormTrangThai_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Clear()
        LoadTT()
    End Sub

    Private Sub LoadTT()
        Dim dt As New DataTable
        dt = TrangThaiDAO.Select_All()
        dgvTrangThai.DataSource = dt
    End Sub

    Private Sub Clear()
        txtTrangThai.Clear()
    End Sub


    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If Not txtTrangThai.Text = "" Then
            Dim TTDTO As New TrangThaiDTO
            TTDTO.TrangThai = txtTrangThai.Text
            If (TrangThaiDAO.Insert(TTDTO) = 1) Then
                MsgBox("Thêm thành công", MsgBoxStyle.OkOnly, "")
            Else
                MsgBox("Thêm không thành công", MsgBoxStyle.OkOnly, "")
            End If
        End If
        Clear()
        LoadTT()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        If dgvTrangThai.SelectedRows.Count > 0 Then
            Dim maTT As Integer
            maTT = Convert.ToInt32(dgvTrangThai.SelectedRows(0).Cells(0).Value.ToString())
            If (TrangThaiDAO.Delete(maTT) = 1) Then
                MsgBox("Xóa thành công", MsgBoxStyle.OkOnly, "")
            Else
                MsgBox("Xóa thất bại", MsgBoxStyle.OkOnly, "")
            End If
        End If
        Clear()
        LoadTT()
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub
End Class